package com.yiwei.jmx.view;

import android.app.Dialog;
import android.content.Context;
import android.content.res.Configuration;
import android.support.v7.widget.RecyclerView;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;

import com.yiwei.jmx.R;
import com.yiwei.jmx.adapter.QuestionUnUseAdapter;
import com.yiwei.jmx.api.Api;
import com.yiwei.jmx.api.bean.QuestionFeedbackBean;
import com.yiwei.jmx.api.model.WechatQuestionUseModel;
import com.yiwei.jmx.util.Network;
import com.yiwei.jmx.util.RxLifeUtil;
import com.yiwei.jmx.util.ToastUtil;
import com.yiwei.jmx.util.Util;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by xsooy-pc on 18-5-22.
 */

public class QuestionUnUseDilaog extends Dialog {


    @BindView(R.id.btn_close)
    ImageView btnClose;
    @BindView(R.id.list)
    RecyclerView list;
    private Context context;
    private QuestionUnUseAdapter adapter;
    private WechatQuestionUseModel.DataBean data;


    public QuestionUnUseDilaog(Context context) {
        this(context, R.style.DialogStyle);
    }

    public QuestionUnUseDilaog(Context context, int themeResId) {
        super(context, themeResId);
        this.context = context;
        initView();
    }

    public void setData(WechatQuestionUseModel.DataBean data) {
        this.data = data;
    }

    @Override
    public void show() {
        super.show();
        adapter.update(data.list);
    }

    private void initView() {
        setContentView(R.layout.dialog_question_unuse);
        ButterKnife.bind(this);
        setCancelable(false);

        Window mWindow = getWindow();
        WindowManager.LayoutParams lp = mWindow.getAttributes();
        lp.width = Util.getDisplayMetrics(context).widthPixels;
        lp.gravity = Gravity.CENTER;
        if (context.getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {// 横屏
            lp.width = (int) (Util.getDisplayMetrics(context).heightPixels * 0.8);
        } else {
            lp.width = (int) (Util.getDisplayMetrics(context).widthPixels * 0.8);
        }
        mWindow.setAttributes(lp);

        adapter = new QuestionUnUseAdapter(context);
        adapter.setOnChooseListener(new QuestionUnUseAdapter.OnChooseListener() {
            @Override
            public void onSuccess(String id) {
                if (onChooseListener != null) {
                    onChooseListener.onSuccess(data.qid, id);
                }
            }
        });
        list.setAdapter(adapter);

    }


    private OnChooseListener onChooseListener;

    public QuestionUnUseDilaog setOnChooseListener(OnChooseListener onChooseListener) {
        this.onChooseListener = onChooseListener;
        return this;
    }

    @OnClick(R.id.btn_close)
    public void onViewClicked() {
        dismiss();
    }


    public interface OnChooseListener {
        void onSuccess(String qid, String id);
    }
}
